//
//  KLWeakDisplayLink.m
//  KLBookCollection
//
//  Created by apple on 2019/1/15.
//  Copyright © 2019年 bonc. All rights reserved.
//

#import "KLWeakDisplayLink.h"
#import <UIKit/UIKit.h>

@interface KLWeakDisplayLink ()
@property (strong, nonatomic) CADisplayLink *link;
@end

@implementation KLWeakDisplayLink

- (void)start {
    if (_link == nil) {
        _link = [CADisplayLink displayLinkWithTarget:self selector:@selector(tickFPS:)];
        [_link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
    }
}

- (void)stop {
    [_link invalidate];
}

- (NSTimeInterval)timestamp {
    return (NSTimeInterval)[_link timestamp];
}

- (void)tickFPS:(id)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(tick:)]) {
        [_delegate tick:self];
    }
}

@end
